<template>
    <!-- pageHeader , route meta :true on hide -->
    <div class="content">
      <div class="page-header-index-wide">
        <slot>
          <!-- keep-alive  -->
          <keep-alive v-if="multiTab">
            <router-view ref="content" />
          </keep-alive>
          <router-view v-else ref="content" />
        </slot>
      </div>
    </div>
</template>

<script>

export default {
  name: 'PageView',
  components: {
  },
  props: {
    avatar: {
      type: String,
      default: null
    },
    title: {
      type: [String, Boolean],
      default: true
    },
    logo: {
      type: String,
      default: null
    },
    directTabs: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      pageTitle: null,
      description: null,
      linkList: [],
      extraImage: '',
      search: false,
      tabs: {},
      multiTab: false
    }
  },
  computed: {},
  mounted () {
    this.tabs = this.directTabs
    this.getPageMeta()
  },
  updated () {
    this.getPageMeta()
  },
  methods: {
    getPageMeta () {
      // eslint-disable-next-line
        this.pageTitle = (typeof(this.title) === 'string' || !this.title) ? this.title : this.$route.meta.title

      const content = this.$refs.content
      if (content) {
        if (content.pageMeta) {
          Object.assign(this, content.pageMeta)
        } else {
          this.description = content.description
          this.linkList = content.linkList
          this.extraImage = content.extraImage
          this.search = content.search === true
          this.tabs = content.tabs
        }
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .content {
    margin: 24px 24px 0;

    .link {
      margin-top: 16px;

      &:not(:empty) {
        margin-bottom: 16px;
      }

      a {
        display: inline-block;
        height: 24px;
        margin-right: 32px;
        line-height: 24px;

        i {
          margin-right: 8px;
          font-size: 24px;
          vertical-align: middle;
        }

        span {
          display: inline-block;
          height: 24px;
          line-height: 24px;
          vertical-align: middle;
        }
      }
    }
  }

  .page-menu-search {
    margin-bottom: 16px;
    text-align: center;
  }

  .page-menu-tabs {
    margin-top: 48px;
  }

  .extra-img {
    width: 195px;
    margin-top: -60px;
    text-align: center;

    img {
      width: 100%;
    }
  }

  .mobile {
    .extra-img {
      width: 96px;
      margin-top: 0;
      text-align: center;

      img {
        width: 100%;
      }
    }
  }
</style>
